/*$.fn.extend({          
     alertWhileClick:function() {            
           $(this).click(function(){                 
                  alert($(this).val());           
            });           
      }       
});*/   
 
//var main = new Object();
//main.menu = new Object();
var mainMenu = {
    min_width: 320,
    min_height: 480,
    win_height: $(window).height() < this.min_height ? this.min_height: $(window).height(),
    win_width: $(window).width() < this.min_width ? this.min_width: $(window).width(),
	doc_width: $(document).width() < this.win_width ? this.win_width: $(document).width(),
	doc_height: $(document).height() < this.win_height ? this.win_height: $(document).height(),
	//li_num: $('.mainMenu').children('li').size()-1, //定义条目数
	menuli:$('.mainMenu').children('li').not('.nav-header'),
	menulia:$('.mainMenu').children('li').not('.nav-header').children('a'),//$('.mainMenu').find('ul').hasClass("dropdown-menu").parent('li'),
	//dropul:$('.mainMenu').children('li').find('ul').hasClass("dropdown-menu"),
	/*win_height: $(window).height() < this.doc_height ? this.doc_height: $(window).height(),
    win_width: $(window).width() < this.doc_width ? this.doc_width: $(window).width(),*/
    init: function() {
        //this.showCont();
        this.resize();
        /*this.posHeader();
        this.mediaquery();*/
        //$(window).on("resize",function() {
//            mainMenu.resize();
//            /*mainMenu.posHeader();
//            mainMenu.mediaquery();*/
//        });
        /*$(window).bind("scroll",
        function() {
            //mainMenu.gotoTop();
            mainMenu.resize();
            //mainMenu.posHeader();
        });*/
        /*this.openNavPanel($("#zxgl"), $("#sub0"));
        this.openNavPanel($("#thyy"), $("#sub1"));
		this.openNavPanel($("#ldps"), $("#sub2"));
		this.openNavPanel($("#cxtj"), $("#sub3"));
		this.openNavPanel($("#sz"), $("#sub4"));
		this.openNavPanel($("#cwgl"), $("#sub5"));*/
		this.openUlPanel();
		//this.dropDownPanel();
    },
    
    /*showCont: function() {
        $("#content").add("#footer").css({
            "display": "block"
        });
    },*/
	
    resize: function() {
        var that = mainMenu;
        //var scroll_len = $(window).scrollTop();
		that.win_height = $(window).height() < that.min_height ? that.min_height: $(window).height();
        that.doc_height = $(document).height() < that.win_height ? that.win_height: $(document).height();
		that.doc_width = $(document).width() < that.win_width ? that.win_width: $(document).width();
		
		
        /*that.win_height = $(window).height() < that.doc_height ? that.doc_height: $(window).height();
        that.win_width = $(window).width() < that.doc_width ? that.doc_width: $(window).width();*/

        /*$(document).css({
            "height": that.doc_height + "px",
            "width": that.doc_width + "px"
        });*/
		$("#main-nav").css({
             "height": that.doc_height + "px"
        });
		//console.log($(document).height());
		/*console.log(that.win_height);
		
		console.log(that.doc_height);*/
		
    },
    
    /*openNavPanel: function(target, panel) {
        $(target).mouseenter(function() {
            $(this).addClass("hover");
			//$('#main-nav').animate({width:"230px"},100);
            $(panel).css({
                "display": "block"
            });
        });
        $(target).mouseleave(function(e) {
			//alert($(e.relatedTarget).attr('id')==panel.attr('id'));
			
			if($(e.relatedTarget).attr('id') == panel.attr('id') || $(e.relatedTarget).parent().attr('id') == panel.attr('id')){
				return;
			}else if($(e.relatedTarget).attr('id')!= target.attr('id')){
				if (navigator.userAgent.indexOf("MSIE 6.0") == -1) {
                    $(this).removeClass("hover");  
					$(panel).css({ "display": "none" }); 
					//$('#main-nav').animate({width:"80px"},100);
                }	
			}	
        });
        $(panel).mouseleave(function(e) {
			//alert($(e.relatedTarget).attr('id')==target.attr('id'));
            if ($(e.relatedTarget).attr('id')!= target.attr('id') || !$(e.relatedTarget).parent().attr('id')!= target.attr('id')) {
                $(target).removeClass("hover");
                $(panel).css({
                    "display": "none"
                });
				//$('#main-nav').animate({width:"80px"},100);
            }
        });
        $("body").not("#main-nav").hover(function() {
            $("#main-nav li").removeClass("hover");
            $("#main-nav .subMenu").css({
                "display": "none"
            });
			//$('#main-nav').animate({width:"80px"},100);
        });
    },*/
	disAllPanel: function() {
		var that = mainMenu;
		that.menulia.each(function(){
			$(this).next(".dropdown-menu").stop(true,true).slideUp('fast');
			$(this).find('span').filter('.glyphicon').removeClass('glyphicon-menu-down').addClass('glyphicon-menu-right');
		});
		
        /*for (i=1;i<=li_num;i++) {    
			//lbmc = eval('LM' + i);
			dropul.hide();
			menuli.removeClass('glyphicon-menu-down').addClass('glyphicon-menu-right');
		}*/
    },
	clBorderleftLi: function() {
		/*var that = mainMenu;
		that.menulia.each(function(){
			$(this).next(".dropdown-menu").children("li").eq(0).removeClass('active');
			$(this).closest('li').removeClass('active');
		});*/
		
		$('.mainMenu').each(function(){
			$('.mainMenu').find("li").removeClass('active');
			/*$('.mainMenu').children(".dropdown-menu").children("li").removeClass('active');*/
		});
    },
	openUlPanel: function() {
		var that = mainMenu;
		/*var lbmc = document.getElementById('LM' + i);
		var wg_pic = document.getElementById('Pic'+i);
		
		if (lbmc.style.display == 'none') {
			//LMYC(i);
			lbmc.style.display = 'block';
			wg_pic.innerHTML="-";
		}else {
			lbmc.style.display = 'none';
			wg_pic.innerHTML="+";	
		}*/
		/*$('.navbar-toggle').click(function(){
			$('.navbar-mobile').slideToggle('slow');
		});*/
		/*$('#navbar-toggle').bind("touchstart", function(){
			$('#main-nav').slideToggle('slow');
		}, false);*/
		/*touch.on('#target', 'hold tap doubletap', function(ev){
			//console.log(ev.type);
		});*/
		touch.on('#navbar-toggle', 'tap', function(ev){
			//console.log(ev.type);
			$('#main-nav').slideToggle('slow');
			ev.preventDefault();
		});
		
		/*var navtoggle=document.getElementById("navbar-toggle"); 	
		var touchStartt = function(){
			if($(this).css("display") == "none"){
		   		$('.navbar-mobile').slideDown('slow');
			}else{
				$('.navbar-mobile').slideUp('fast');
			}
			
		};
		navtoggle.addEventListener("touchstart", touchStartt, false);*/
		 
		/*that.menulia.on("click",function(){
			if ($(this).next(".dropdown-menu").css("display") == "block"){
				that.disAllPanel();	
			}else {  // $(this).next(".dropdown-menu").css("display") == "none" || $(this).children().hasClass("dropdown-menu") == false 
				that.disAllPanel();
				if($(this).next(".dropdown-menu").css("display") == "none"){
					$(this).next(".dropdown-menu").stop(true,true).slideDown('slow');
					$(this).find('span').filter('.glyphicon').removeClass('glyphicon-menu-right').addClass('glyphicon-menu-down');
				};					
				
				if($(this).closest('li').hasClass('active') == false){
					that.clBorderleftLi();
					$(this).closest('li').addClass('active');
					if($(this).next(".dropdown-menu")){
						$(this).next(".dropdown-menu").children("li").eq(0).addClass('active');
					}else{}				
				}
				
			};
		});*/
		touch.on(that.menulia, 'tap', function(ev){
			
			if ($(this).next(".dropdown-menu").css("display") == "block"){
				that.disAllPanel();	
			}else {  // $(this).next(".dropdown-menu").css("display") == "none" || $(this).children().hasClass("dropdown-menu") == false 
				that.disAllPanel();
				if($(this).next(".dropdown-menu").css("display") == "none"){
					$(this).next(".dropdown-menu").stop(true,true).slideDown('slow');
					$(this).find('span').filter('.glyphicon').removeClass('glyphicon-menu-right').addClass('glyphicon-menu-down');
				};					
				
				if($(this).closest('li').hasClass('active') == false){
					that.clBorderleftLi();
					$(this).closest('li').addClass('active');
					if($(this).next(".dropdown-menu")){
						$(this).next(".dropdown-menu").children("li").eq(0).addClass('active');
					}else{}				
				}
				
			};
			ev.preventDefault();
		});
			
		$("#dropdown-toggle").hover(function(){
			$(".pop-menu").stop(true,true).slideDown();
		},function(){
			$(".pop-menu").stop(true,true).slideUp();
		});
			
		/*touch.on('#dropdown-toggle', 'tap', function(ev){
			$(".pop-menu").stop(true,true).slideToggle();
		});
		touch.on('#dropdown-toggle', 'touchstart touchmove touchend', function(ev){
			//console.log(ev.type);
			if(ev.type == 'touchstart' || ev.type == 'touchmove'){
				$(".pop-menu").stop(true,true).slideDown();
			}
			if(ev.type == 'touchend'){
				$(".pop-menu").stop(true,true).slideUp();
			}
			
			ev.preventDefault();
		});*/
		
		
		
		/*$("#dropdown-toggle").click(function(){
			if($(".pop-menu").css("display") == "none"){
				$(".pop-menu").slideDown();
			}else{
				$(".pop-menu").slideUp();
			}
		});*/

		touch.on('.pop-menu > li', 'tap', function(ev){
			if($(this).hasClass('active') == false){	
				$(this).siblings('.active').removeClass('active');
				$(this).addClass('active');			
			}
		});
		
		touch.on('.dropdown-menu > li', 'tap', function(ev){
			$(this).siblings().removeClass('active');
			$(this).addClass('active');
		});

    }/*,
	
	dropDownPanel: function() {
		
	}*/
	
	

 
    /*openVersionPanel: function() {
        var pro_e = $(".pr-info .m-v");
        var panel = $(".pr-info .m-v-panel");
        $(pro_e).hover(function() {
            $(this).next(".m-v-panel").css({
                "display": "block"
            });
        });
        $(panel).hover(function() {},
        function() {
            $(this).css({
                "display": "none"
            });
        });
    },
    
    gotoTop: function() {
        if ($(document).scrollTop() == 0) {
            $(".goto").hide();
            return;
        }
        if (navigator.userAgent.indexOf("MSIE 6.0") != -1) {
            var scrollTop = $(window).scrollTop() + $(window).height() - 80;
            if (scrollTop < 0) {
                scrollTop = 0;
            };
            $(".goto").css({
                "top": scrollTop + "px"
            }).show();
        } else {
            $(".goto").css({
                "bottom": "0"
            }).show();
        }
    },
    downloadAct: function(c_T) {
        $("#banner .download").hover(function() {
            $("#banner .download span").css({
                "top": "-48px"
            }).animate({
                "top": "48px"
            },
            c_T,
            function() {
                $("#banner .download span").css({
                    "top": "-14px"
                }).animate({
                    "top": "0"
                },
                c_T / 4);
            })
        },
        function() {});
    },
    scrollDown: function(c_T) {
        $(".scroll span").click(function() {
            var height = $(window).height();
            tmp_height = height - $(window).scrollTop();
            $("body").animate({
                "top": "-" + tmp_height + "px"
            },
            c_T,
            function() {
                $("body").css({
                    "top": "0"
                });
                $(window).scrollTop(height);
                mainMenu.posHeader();
            });
        });
    }*/
};